'use strict';

const AdminBaseController = require("../base");
class SystemPermissionController extends AdminBaseController {
    static get serviceName() {
        return 'system.systemPermission';
    }
    async getUserRoles() {
        const { ctx } = this;
        const { userId } = ctx.query;
        const result = await this.service.getUserRoles(userId);
        this.ctx.success(result);
    }

    async updateUserRoles() {
        const { ctx } = this;
        const {
            userId,
            roleIds,
        } = ctx.request.body;
        const result = await this.service.updateUserRoles(userId, roleIds);
        this.ctx.success(result);
    }
    async listRoleMenus() {
        const { ctx } = this;
        const { roleId } = ctx.query;
        const result = await this.service.listRoleMenus(roleId);
        this.ctx.success(result);
    }
    async updateRoleMenus() {
        const { ctx } = this;
        const {
            roleId,
            menuIds,
        } = ctx.request.body;
        const result = await this.service.updateRoleMenus(roleId, menuIds);
        this.ctx.success(result);
    }
}

module.exports = SystemPermissionController;
